package com.wty.gw.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wty.gw.model.Do.CompanyDO;
import com.wty.gw.model.query.CompanyQuery;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.InitBinder;

import com.wty.gw.util.ResponseData;


import com.wty.gw.service.CompanyService;


import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping("/company")
public class CompanyController{
	
	@Autowired
	private CompanyService companyService;
	
	

    @ResponseBody
    @RequestMapping("/add")
    public ResponseData add(CompanyDO companyDo) {
        companyService.add(companyDo);
        return ResponseData.success("操作成功！");
    }

    @ResponseBody
    @RequestMapping("/delete")
    public ResponseData delete(Long id) {
        companyService.delete(id);
        return ResponseData.success("操作成功！");
    }

    @ResponseBody
    @RequestMapping("/update")
    public ResponseData update(CompanyDO companyDo) {
        companyService.update(companyDo);
        return ResponseData.success("操作成功！");
    }

    @ResponseBody
    @RequestMapping("/get")
    public ResponseData get(Long id) {
        return ResponseData.success("操作成功！", companyService.get(id));
    }

    @ResponseBody
    @RequestMapping("/list")
    public ResponseData list(CompanyQuery query) {
        return ResponseData.success("操作成功！", companyService.listByPage(query));
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));


    }
}